package com.newasia.server.common.checkHandler;

import com.newasia.server.controller.form.UserForm;

public abstract class CheckHandler<T> {

    protected CheckHandler next;
    public void next(CheckHandler next){ this.next = next;}

    public abstract void doHandler(UserForm form);

    public static class Builder<T>{
        private CheckHandler<T> head;
        private CheckHandler<T> tail;

        public Builder<T> addHandler(CheckHandler handler){
            do {
                if (this.head == null) {
                    this.head = this.tail = handler;
                    break;
                }
                this.tail.next(handler);
                this.tail = handler;
            }while (false);//真正框架中，如果是双向链表，会判断是否已经到了尾部
            return this;
        }
        public CheckHandler<T> build(){
            return this.head;
        }
    }
}
